package middleware

import (
	"easyVolunteer/model"
	"easyVolunteer/utils/code"
	"easyVolunteer/utils/errno"
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"strconv"
)

func Admin() gin.HandlerFunc {
	return func(c *gin.Context) {
		userId, _ := strconv.Atoi(c.Query("userID"))
		fmt.Println(userId)
		role, _ := model.GetUserRole(uint64(userId))

		if role != code.AdminRole {
			c.JSON(http.StatusForbidden, gin.H{
				"code": errno.ErrUserNotRights.Code,
				"msg":  errno.ErrUserNotRights.Message,
			})
			c.Abort()
			return
		}
	}
}
